import { Controller, Inject, Get, Query, Body, Post, Put, Param, Del } from '@midwayjs/core';
import { PostService } from "@service/system/post.service";
import { ListPostDTO, CreatePostDTO, UpdatePostDTO } from "@dto/system/post.dto";
import { Auth } from "@decorator/auth.decorator";
import { Log, BusinessType } from "@decorator/log.decorator";

@Controller('/system/post')
export class PostController {
  @Inject()
  postService: PostService;

  // 获取列表
  @Auth('system:post:list')
  @Get('/list')
  async list(@Query() queryParams: ListPostDTO) {
    return await this.postService.list(queryParams);
  }

  // 新增
  @Auth('system:post:add')
  @Log({ title: '岗位管理', businessType: BusinessType.ADD })
  @Post('/')
  async create(@Body() post: CreatePostDTO) {
    return await this.postService.create(post);
  }

  // 删除
  @Auth('system:post:remove')
  @Log({ title: '岗位管理', businessType: BusinessType.REMOVE })
  @Del('/:postId')
  async delete(@Param('postId') postId: string) {
    return await this.postService.delete(postId);
  }

  // 修改
  @Auth('system:post:edit')
  @Log({ title: '岗位管理', businessType: BusinessType.EDIT })
  @Put('/')
  async update(@Body() post: UpdatePostDTO) {
    return await this.postService.update(post);
  }

  // 获取详情
  @Auth('system:post:query')
  @Get('/:postId')
  async get(@Param('postId') postId: number) {
    return await this.postService.detail(postId);
  }

  // 导出
  @Auth('system:post:export')
  @Log({ title: '岗位管理', businessType: BusinessType.EXPORT })
  @Post('/export')
  async export(@Body() queryParams: ListPostDTO) {
    return await this.postService.export(queryParams);
  }
}
